package cn.com.yang.egg;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Desc<...>
 * @Author 杨亿金
 * @Date 2021/1/29 14:57
 * @CopyRight
 * @Version
 */
public class EggAtomicInteger {
    public  static AtomicInteger race = new AtomicInteger(0);
    public static void inCreate(){
        race.incrementAndGet();
    }
    private static final int THREADS_COUNT = 20;

    public static void main(String[] args) {
        Thread [] threads = new Thread[THREADS_COUNT];
        for (int i=0;i<THREADS_COUNT;i++){
            threads[i]=new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int j=0;j<10000;j++){
                        inCreate();
                    }
                }
            });
            threads[i].start();
        }
        while (Thread.activeCount()>1)Thread.yield();
        System.out.println(race);
    }
}
